import time

from django.db import models
from django.contrib.auth.models import AbstractUser


# 自定义用户表
class CustomUser(AbstractUser):
    nickname = models.CharField('昵称', max_length=32)
    picture = models.ImageField('图片', upload_to='pic/%Y%m%d/', blank=True)
    phone = models.CharField('手机号', max_length=11, default='', help_text='用户手机号')
    integral = models.IntegerField('积分', help_text='用户积分')
    invitation_code = models.CharField('邀请码', max_length=50, default='', help_text='邀请码')
    invitation_count = models.IntegerField('邀请次数', default=0, help_text='邀请次数')
    created = models.DateTimeField(auto_created=True, help_text='创建时间')

    class Meta:
        db_table = 'users'
        verbose_name = '用户'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


# 标准用户表
class StdUser(models.Model):
    username = models.CharField('昵称', max_length=32)
    phone = models.CharField('手机号', max_length=11, unique=True, default='')
    password = models.CharField('密码', max_length=255)

    class Meta:
        db_table = 'syl_stduser'
        verbose_name = '标准用户表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


# 用户表
class User(models.Model):
    nickname = models.CharField('昵称', max_length=32)
    email = models.CharField('邮箱', max_length=50)
    password = models.CharField('密码', max_length=255)

    class Meta:
        db_table = 'syl_user'
        verbose_name = '用户表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.nickname


# 验证码
class ValidCodeModel(models.Model):
    email = models.CharField(max_length=32)
    code = models.CharField(max_length=32)
    losetime = models.DecimalField(
        decimal_places=8,
        max_digits=20,
        default=time.time() + 300
    )

    class Meta:
        db_table = "validcode"

# Create your models here.
